<!-- BEGIN PAGE HEADER-->
<?php $this->load->view('partials/breadcrumb.tpl') ?>
<!-- END PAGE HEADER-->

<div class="row">
    <div class="col-xs-12">
        <!-- Begin: life time stats -->
        <div class="portlet">
            <?= form_open('', Array('class' => 'form-inline', 'role' => 'form')) ?>
            <?= search_form_input('product_name', filterValue('product_name'), '商品名称', 'class="form-control input-xs"'); ?>
            <?= search_form_input('purchase_person', filterValue('purchase_person'), '采购人', 'class="form-control input-xs"'); ?>
            <?= search_form_input('batch', filterValue('batch'), '商品批次', 'class="form-control input-xs"'); ?>
            <?= search_form_dropdown('shop_id', array('' => '选择账户...') + $allShops, filterValue('shop_id'), '所属账户', 'class="form-control input-xs select2me new-select"'); ?>

            <?= search_form_dropdown('in_mark', array('' => '入库方式...') + IOSS_StaticConfig::getShippingInType(), filterValue('in_mark'), '入库方式', 'class="form-control input-xs"'); ?>
            <?= search_form_dropdown('warehouse', array('' => '存储仓库...') + IOSS_StaticConfig::getShippingWarehouse(), filterValue('warehouse'), '存储仓库', 'class="form-control input-xs"'); ?>
            <?= search_form_dropdown('in_status', array('' => '状态...') + MShippingIn::getState(), filterValue('in_status'), '状态', 'class="form-control input-xs"'); ?>

            <div style="clear:both;height:14px;"></div>
            <?= search_form_input('in_number_perpage', filterValue('in_number_perpage'), '每页显示条数', 'class="form-control input-xs"'); ?>
            <?= search_form_dropdown('in_order_type', array('' => '排序方式...') + MShippingIn::getOrderType(), filterValue('in_order_type'), '排序', 'class="form-control input-xs"'); ?>
            <div class="input-group input-large date-picker input-daterange" data-date="" data-date-format="yyyy-mm-dd">
                <input type="text" class="form-control" name="in_create_time_begin"
                       value="<?= filterValue('in_create_time_begin') ?>" placeholder="采购开始时间" autoComplete="off">
                <span class="input-group-addon">to </span>
                <input type="text" class="form-control" name="in_create_time_end"
                       value="<?= filterValue('in_create_time_end') ?>" placeholder="采购结束时间" autoComplete="off">
            </div>

            <button type="button" class="btn default" id="reset">重置条件</button>
            <button type="submit" class="btn green about_search">搜索 <i class="fa fa-search"></i></button>
            <button type="button" class="btn blue" id="out">出库</button>

            <?= form_close() ?>
            <div class="portlet-body">
                <div class="row">
                    <div class="col-xs-12">
                        <div class="table-scrollable">
                            <form action="<?= site_url('shipping/warehouse_out/add') ?>" method="post" id="app-ids">
                                <table class="table table-striped table-bordered table-hover">
                                    <thead class="flip-content">
                                    <tr>
                                        <th width="1%">
                                            <label>
                                                <input type="checkbox" id="merge_all" ">
                                            </label>
                                        </th>
                                        <th>ID</th>
                                        <th>采购日期</th>
                                        <th>所属账户</th>
                                        <th>商品批次</th>
                                        <th>入库方式</th>
                                        <th>商品名称</th>
                                        <th>商品单价</th>
                                        <th>商品数量</th>
                                        <th>剩余数量</th>
                                        <th>商品总价</th>
                                        <th>采购人</th>
                                        <th>录入人</th>
                                        <th>存储仓</th>
                                        <th>入库状态</th>
                                        <th>创建时间</th>
                                        <th>操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <?php foreach ($list as $v) { ?>
                                        <tr>
                                            <td>
                                                <?php if ($v->left_quantity && $v->in_status == 1): ?>
                                                <input type="checkbox" class="mbox" name="in_ids[]" value="<?= $v->id ?>" title="ID:<?= $v->id ?>">
                                        <?php endif; ?>
                                            </td>
                                            <td class="numeric"><?= $v->id ?></td>
                                            <td class="numeric"><?= date('Y-m-d', $v->purchase_time) ?></td>
                                            <td class="numeric"><?= $allShops[$v->shop_id] ?></td>
                                            <td class="numeric"><?= htmlspecialchars($v->batch) ?></td>
                                            <td class="numeric"><label class="label label-primary"><?= IOSS_StaticConfig::getShippingInType($v->in_mark) ?></label></td>
                                            <td class="numeric"><?= htmlspecialchars($v->product_name) ?></td>
                                            <td class="numeric"><?= $v->product_price ?></td>
                                            <td class="numeric"><?= $v->product_quantity ?></td>
                                            <td class="numeric"><span class="left-number"><?= $v->left_quantity ?></span></td>
                                            <td class="numeric"><?= $v->product_amount ?></td>
                                            <td class="numeric"><?= htmlspecialchars($v->purchase_person) ?></td>
                                            <td class="numeric"><?= $allPurchaser[$v->operator_id] ?></td>
                                            <td class="numeric"><?= IOSS_StaticConfig::getShippingWarehouse($v->warehouse) ?></td>
                                            <td class="numeric"><?= MShippingIn::getState($v->in_status) ?></td>
                                            <td class="numeric"><?= date('Y-m-d H:i', $v->create_time) ?></td>
                                            <td class="numeric text-center">
                                                <div class="btn-group btn-group-solid">
                                                    <a href="<?= site_url($thisModule . $thisController . '/view/' . $v->id) ?>"
                                                       class="btn btn-sm blue"><i class="fa fa-play"></i> 查看
                                                    </a>
                                                    <a href="<?= site_url($thisModule . $thisController . '/edit/' . $v->id) ?>"
                                                       class="btn btn-sm purple">
                                                        <i class="fa fa-edit"></i> 编辑
                                                    </a>

                                                    <a href="javascript:void(defConfirm('<?= site_url($thisModule . 'warehouse_in/delete/' . $v->id . '/' . $v->update_time) ?>'));"
                                                       class="btn btn-sm red ">
                                                        <i class="fa fa-minus-square"></i> 删除
                                                    </a>

                                                </div>
                                            </td>
                                        </tr>
                                    <?php } ?>
                                    </tbody>
                                </table>
                            </form>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-xs-12 text-right">
                        <?= $pagination ?>
                    </div>
                </div>
            </div>
        </div>
        <!-- End: life time stats -->
    </div>
</div>
<script>


    function defConfirm(url) {
        if (!confirm("谨慎操作，删除后不可撤回，确定要删除吗？")) {
            return false;
        }
        window.location.href = url;
        return true;
    }
    $(document).ready(function () {
        $("#out").click(function () {
            var ids_form = $("#app-ids");
            var data = ids_form.serialize();
            if (data.indexOf('in_ids') == -1){
                toastr.error('请选择要出库的记录！');
                return;
            }
            ids_form.submit();
        });

        $('#merge_all').click(function () {
            if ($(this).prop("checked") == true) {
                $(".mbox").prop('checked', true);
                $(".mbox").parent('span').addClass('checked');
                return;
            } else {
                $(".mbox").prop('checked', false);
                $(".mbox").parent('span').removeClass('checked');
                return;
            }
        });


        $("#reset").click(function () {
            var SelectShop = $("select[name='shop_id']");
            var shop = SelectShop[0].options[0].text;
            var v_span = $('.select2-chosen');
            v_span.eq(0).html(shop);
            var SelectArr = $("select");
            $("input[type='text']").val('');
            SelectArr.val('');
        });

    });
</script>